<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%@ taglib prefix="d" uri="http://dgg.net/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <title></title>
    <c:import url="../../header.jsp"/>
</head>
<body>
<div class="content-warp">
    <div class="screen-tab-warp">
        <ul class="screen-tab">
            <li class="active" onclick="tableSwitch(this,1)"><a href="javascript:void(0)">权证人员工作量</a></li>
            <li onclick="tableSwitch(this,2)"><a href="javascript:void(0)">资料人员工作量</a></li>
            <li onclick="tableSwitch(this,3)"><a href="javascript:void(0)">评估人员工作量</a></li>
            <li onclick="tableSwitch(this,4)"><a href="javascript:void(0)">驻点人员工作量</a></li>
        </ul>
    </div>
    <div class="dgg-list-top-warp">
        <div class="screen-search">
            <ul>
                <li>
                    <label>综合查询：</label>
                    <input type="text" class="dggui-input dggui-input-normal" id="IntegratedQuery" name="IntegratedQuery" placeholder="客户名称/订单编号/生产编号">
                </li>
                <li>
                    <label id="blsj">办理时间：</label>
                    <input type="text" readonly class="dggui-input dggui-time-range" id="handleTime" name="handleTime">
                    <i class="iconfont icon-rili"></i>
                </li>
                <li>
                    <label>办理人员：</label>
                    <select id="manageUserId" name="manageUserId" style="min-width: 80px; display: none;">
                    </select>
                </li>
                <li>
                    <label>所属生产事业部：</label>
                    <select id="productOrgId" name="productOrgId">
                    </select>
                </li>
                <li>
                    <button class="dggui-btn searchBtn" onclick="tableReload();return false;">搜索</button>
                    <button class="dggui-btn dggui-btn-primary" onclick="cleanSearch();return false;">清空条件</button>
                    <d:hasUrlAuth authCode="RZSC_OPERATION_EXPORT">
                        <button class="dggui-btn dggui-btn-green"
                                onclick="excelExport('${basePath}/order_detail/excel_export_all.do');return false;">导出
                        </button>
                    </d:hasUrlAuth>
                </li>
            </ul>
        </div>
    </div>
    <div class="list-content">
        <div class="table-warp">
            <table class="dggui-table" id="fieldWorkLoadDataList">
            </table>
        </div>
        <input type="hidden" id="recordType" value="${recordType}">
    </div>
</div>
<c:import url="/WEB-INF/jsp/footer.jsp"/>
<script>
    var tables;
    dggui.use(['table', 'select2', 'dggdate'], function () {
        var table = dggui.table;
        var select2 = dggui.select2;
        var dggdate = dggui.dggdate;
        //初始化所属生产事业部
        syb("#productOrgId");
        select2.render({
            placeholder: "请选择",
            elem: $('#productOrgId'),
            allowClear: true,
            width: "160px"
        });
        //初始化流程人员
        initUser("RZSC_FLOW_USER", "role", "#manageUserId");
        select2.render({
            placeholder: "请选择",
            allowClear: true,
            elem: $('#manageUserId'),
            width: "160px"
        });
        //初始化时间
        dggdate.render({
            elem: '#handleTime',
            type: 'date',
            range: '~'
        });
        loadTable();
        // 处理dataTable 异常错误信息
        $.fn.dataTable.ext.errMode = 'none';//不抛出异常
        tables.on('error.dt', function (e, settings, techNote, message) {
            //dggui.dialog.errors("表格查询错误，请联系管理员", 2000);
            if (checkEmpty(settings.jqXHR.responseJSON.error)) {
                dggui.dialog.errors(settings.jqXHR.responseJSON.error, 2000);
            }
        });
    });

    function loadTable(){
        var opt = {
            "elem": "#fieldWorkLoadDataList",
            "ajax": sysInfo.basePath + "/order_detail/field_work_load_data_list.do",
            "scrollX": "true",//是否开启横项滚动
            //"selectCheck": false, //多选,同时选中复选框
            "oneSelectCheck": true,//单选，同时选中复选框
            "fixedColumns": {//锁定列，只有开启scrollX时才生效
                "leftColumns": 4,//左侧锁定2列
                "rightColumns": 1//右侧锁定1列
            },
            "visible": true,
            "fnServerParams": function (aoData) {
                // var moneyMax = $("#moneyMax").val().trim();
                // var moneyMin = $("#moneyMin").val().trim();
                //搜索条件
                aoData = $.extend(aoData, {
                    IntegratedQuery: $("#IntegratedQuery").val(),
                    handleTime: $("#handleTime").val(),
                    manageUserId: $("#manageUserId").val(),
                    productOrgId: $("#productOrgId").val(),
                    recordType:$("#recordType").val()
                    }
                )
                return aoData;
            },
            "aoColumns": getData($("#recordType").val())
        };
        tables = dggui.table.render(opt);
    }

    //查询
    function tableReload() {
        tables.ajax.reload();
    }
    //切换Table
    function tableSwitch(obj,recordType) {
        $(obj).attr("class","active");
        $(obj).siblings().attr("class","");
        if(recordType == 1){
            $("#recordType").val(1)
            $("#blsj").text("办理时间：");
        }else if(recordType == 2){
            $("#recordType").val(2)
            $("#blsj").text("办理时间：");
        }else if(recordType == 3){
            $("#recordType").val(3)
            $("#blsj").text("办理时间：");
        }else if(recordType == 4){
            $("#recordType").val(4)
            $("#blsj").text("放款时间：");
        }
        cleanSearch();
        tables.destroy(true);
        $('.table-warp').append('<table class="dggui-table" id="fieldWorkLoadDataList"></table>');
        loadTable();
    }
    //页面展示字段
    function getData(recordType){
        var data = [{
            "sClass": "check-th",
            "title": "<input type='checkbox' class='checkall'>",
            "orderable": false,
            "render": function (data, type, full, meta) {
                return '<input type="checkbox" class="checkchild" name="checkchild" value="' + data + '">';
            }
            },
            {
                "title": "序号",
                "orderable": false,
                "render": function (data, type, full, meta) {
                    return meta.row + 1;
                }
            },
            {
                "title": "订单编号",
                "orderable": false,
                "data": "orderNo",
                "render": function (data, type, full, meta) {
                    return ('<a href="javascript:;" class="dggui-link"  onclick="openBusinessDetail(\'' + full.orderNo + '\',\'' + full.orderId + '\')" /><span>' + data + '</span></a>');
                    /*return data;*/
                }
            },
            {
                "title": "生产订单编号",
                "orderable": false,
                "data": "scProductOrderNo",
                "render": function (data, type, full, meta) {
                    var result = "";
                    result += '<a href="javascript:;"  class="dggui-link" onclick="openOrderInfoDetail(\'' + full.scProductOrderNo + '\',\'' + full.scProductOrderId + '\')" /><span>' + data + '</span></a>';
                    return result;
                }
            },
            {
                "title": "客户",
                "orderable": false,
                "data": "customerName",
                "render": function (data, type, full, meta) {
                    return emptyStringConvert(full.customerName);
                }
            },
            {
                "title": "生产状态",
                "orderable": false,
                "data": "status",
                "render": function (data, type, full, meta) {
                    return data ? data : '';
                }
            },
            {
                "title": "流程人员",
                "orderable": false,
                "data": "flowUserName",
                "render": function (data, type, full, meta) {
                    return emptyStringConvert(full.flowUserName);
                }
            },
            {
                "title": "办理人员",
                "orderable": false,
                "data": "manageUserName",
                "render": function (data, type, full, meta) {
                    return data ? data : '';
                }
            }
        ]
        var beforeData = [];
        if(recordType == 1){
            beforeData = [
                {
                    "title": "办理类型",
                    "orderable": false,
                    "data": "handleTypeValue",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {
                    "title": "办理区域",
                    "orderable": false,
                    "data": "handleAreaValue",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {
                    "title": "办理地点",
                    "orderable": false,
                    "data": "handlePlace",
                    "render": function (data, type, full, meta) {
                        return '<div class="line1" title="' + data + '"><p>' + strInterception(data, 10) + '</p></div>'
                    }
                },
                {
                    "title": "办理日期",
                    "orderable": false,
                    "data": "handleTime",
                    "render": function (data, type, full, meta) {
                        return data ? fmtTime(data) : '';
                    }
                }];
        }else if(recordType == 2){
            beforeData = [
                {
                    "title": "银行",
                    "orderable": false,
                    "data": "bank",
                    "render": function (data, type, full, meta) {
                        return '<div class="line1" title="' + data + '"><p>' + strInterception(data, 10) + '</p></div>'
                    }
                },
                {
                    "title": "办理类型",
                    "orderable": false,
                    "data": "handleTypeValue",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {
                    "title": "办理数量",
                    "orderable": false,
                    "data": "handleNum",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {
                    "title": "办理日期",
                    "orderable": false,
                    "data": "handleTime",
                    "render": function (data, type, full, meta) {
                        return data ? fmtTime(data) : '';
                    }
                }];
        }else if(recordType == 3){
            beforeData = [
                {
                    "title": "银行",
                    "orderable": false,
                    "data": "bank",
                    "render": function (data, type, full, meta) {
                        return '<div class="line1" title="' + data + '"><p>' + strInterception(data, 10) + '</p></div>'
                    }
                },
                {
                    "title": "评估公司",
                    "orderable": false,
                    "data": "assessmentCompany",
                    "render": function (data, type, full, meta) {
                        return '<div class="line1" title="' + data + '"><p>' + strInterception(data, 10) + '</p></div>'
                    }
                },
                {
                    "title": "办理日期",
                    "orderable": false,
                    "data": "handleTime",
                    "render": function (data, type, full, meta) {
                        return data ? fmtTime(data) : '';
                    }
                }];
        }else if(recordType == 4){
            beforeData = [
                {
                    "title": "渠道",
                    "orderable": false,
                    "data": "channelName",
                    "render": function (data, type, full, meta) {
                        return '<div class="line1" title="' + data + '"><p>' + strInterception(data, 10) + '</p></div>'
                    }
                },
                {
                    "title": "放款金额",
                    "orderable": false,
                    "data": "loanMoney",
                    "render": function (data, type, full, meta) {
                        var htm = '<div class="order-render">';
                        if (null == data || undefined == data) {
                            htm += '<p><span> - </span></p>';
                        } else {
                            htm += '<p><span>' + data + '</span></p>';
                        }
                        return htm;
                    }
                },
                {
                    "title": "放款日期",
                    "orderable": false,
                    "data": "loanTime",
                    "render": function (data, type, full, meta) {
                        return data ? fmtTime(data) : '';
                    }
                }];
        }
        data = mergeArray(data,beforeData);
        var cz =[
            {
                "title": "生产事业部",
                "orderable": false,
                "data": "productOrgName",
                "render": function (data, type, full, meta) {
                    return data ? data : '';
                }
            },
            {
                "title": "备注",
                "orderable": false,
                "data": "remark",
                "render": function (data, type, full, meta) {
                    return '<div class="line1" title="' + data + '"><p>' + strInterception(data, 10) + '</p></div>'
                }
            },
            {
                'title': '操作',
                "orderable": false,
                "render": function (data, type, row, meta) {
                var htm = '<a href="javascript:void(0)" class="dggui-link" onclick="workEntryOrder(\''+row.id+'\')">编辑</a>&nbsp;<a href="javascript:void(0)" class="dggui-link" onclick="removeWorkEntryOrder(\''+row.id+'\')">删除</a>';
                return htm;
                }
            }]
        data = mergeArray(data,cz);
        return data;
    }
    
    function mergeArray(arr1,arr2) {
        if(arr2.length>0){
            for(var i = 0;i < arr2.length;i++){
                arr1.push(arr2[i])
            }
        }
        return arr1;
    }
</script>
<script>

    //工作录入记录删除
    function removeWorkEntryOrder(id) {
        dggui.dialog.confire('确认执行此操作？', '操作提示', function () {
            dggui.dialog.loading();
            $.ajax({
                url: sysInfo.basePath + "/order_detail/work_entry_delete.do",
                data: {id: id},
                success: function (res) {
                    dggui.dialog.loading('close');
                    if (res.code == 0) {
                        dggui.dialog.succeed(res.msg);
                        tableReload();
                    } else {
                        dggui.dialog.errors(res.msg);
                    }
                }
            });

        })
    }

    //工作录入编辑
    function workEntryOrder(id) {
        dggui.dialog.loading();
        $.ajax({
            url: sysInfo.basePath + "/order_detail/work_entry_update_page.html",
            dataType: 'html',
            data: {id: id},
            success: function (res) {
                dggui.dialog.loading('close');
                var title  ="";
                var recordType = $("#recordType").val()
                if(recordType == 1){
                    title = "权证人员工作量编辑"
                }else if(recordType == 2){
                    title = "资料人员工作量作编辑"
                }else if(recordType == 3){
                    title = "评估人员工作量编辑"
                }else{
                    title = "驻点人员工作量编辑"
                }
                dggui.dialog.open({
                    title: title,
                    content: res,
                    area: '1000px',
                    btn: ["确定", "取消"],
                    yes: function (index) {
                        var params = serializeObject($('#workEntryTable'));
                        var verify = [];
                        //根据录入类型选择校验的字段
                        if(params.recordType == 1){
                            verify = [
                                {
                                    "name": "handleTime",//验证字段名
                                    "type": [1],// 1 验证是否为空 2 是否有特殊字符  3 验证长度时候在指定范围 同时传mix和max参数 4 只能输入正整数
                                    "msg": "办理时日期"//提示信息
                                },
                                {
                                    "name": "handleArea",
                                    "type": [1],
                                    "msg": "办理区域"
                                },
                                {
                                    "name": "handleType",
                                    "type": [1],
                                    "msg": "办理类型"
                                },
                                {
                                    "name": "handlePlace",
                                    "type": [1],
                                    "mix" : 1,
                                    "max" : 50,
                                    "msg": "办理地点"
                                },
                                {
                                    "name": "remark",
                                    "type": [5],
                                    "mix" : 0,
                                    "max" : 120,
                                    "msg": "备注"
                                }
                            ]
                        }else if(params.recordType == 2){
                            verify = [
                                {
                                    "name": "handleTime",
                                    "type": [1],
                                    "msg": "办理时日期"
                                },
                                {
                                    "name": "bank",
                                    "type": [1],
                                    "mix" : 1,
                                    "max" : 25,
                                    "msg": "银行"
                                },
                                {
                                    "name": "handleType",
                                    "type": [1],
                                    "msg": "办理类型"
                                },
                                {
                                    "name": "handleNum",
                                    "type": [1,4],
                                    "mix" : 1,
                                    "max" : 10,
                                    "msg": "办理数量"
                                },
                                {
                                    "name": "remark",
                                    "type": [5],
                                    "mix" : 0,
                                    "max" : 120,
                                    "msg": "备注"
                                }
                            ]
                        }else if(params.recordType == 3){
                            verify = [
                                {
                                    "name": "handleTime",
                                    "type": [1],
                                    "msg": "办理时日期"
                                },
                                {
                                    "name": "assessmentCompany",
                                    "type": [1],
                                    "mix" : 1,
                                    "max" : 120,
                                    "msg": "评估公司"
                                },
                                {
                                    "name": "bank",
                                    "type": [1],
                                    "mix" : 1,
                                    "max" : 25,
                                    "msg": "银行"
                                },
                                {
                                    "name": "remark",
                                    "type": [5],
                                    "mix" : 0,
                                    "max" : 120,
                                    "msg": "备注"
                                }
                            ]
                        }else if(params.recordType == 4){
                            verify = [
                                {
                                    "name": "loanTime",
                                    "type": [1],
                                    "msg": "放款日期"
                                },
                                {
                                    "name": "loanMoney",
                                    "type": [6],
                                    "mix" : 1,
                                    "max" : 20,
                                    "msg": "放款金额"
                                },
                                {
                                    "name": "productName",
                                    "type": [1],
                                    "mix" : 1,
                                    "max" : 120,
                                    "msg": "产品名称"
                                },
                                {
                                    "name": "channelName",
                                    "type": [1],
                                    "mix" : 1,
                                    "max" : 25,
                                    "msg": "渠道"
                                },
                                {
                                    "name": "remark",
                                    "type": [5],
                                    "mix" : 0,
                                    "max" : 120,
                                    "msg": "备注"
                                }
                            ]
                        }
                        if (!verifyObject(verify, params)) {
                            return false;
                        }
                        $.ajax({
                            url: sysInfo.basePath + "/order_detail/work_entry_update.do",
                            data: {
                                pofwlJson: JSON.stringify(params)
                            },
                            success: function (res) {
                                dggui.dialog.loading('close');
                                if (res.code == 0) {
                                    dggui.dialog.succeed("修改成功");
                                    layer.close(index);
                                    tableReload();
                                } else {
                                    dggui.dialog.errors(res.msg);
                                }
                            }
                        });
                    }, btn2: function () {
                    }
                })
            }
        });
    }
    //格式化时间为只展示日期
    function fmtTime(val) {
        var date = new Date(val);
        return date.format("yyyy-MM-dd")
    }

    function excelExport(url) {
        var obj = new Object();
        obj.IntegratedQuery= $("#IntegratedQuery").val();
        obj.handleTime= $("#handleTime").val();
        obj.manageUserId=$("#manageUserId").val();
        obj.productOrgId=$("#productOrgId").val();
        obj.recordType=$("#recordType").val();
        var arr = ['recordType']
        formSubmit(url, obj, arr);
    }


</script>
</body>
</html>